#ifndef _DICOM_STORAGE_ENCRYPT_STREAM_H_
#define _DICOM_STORAGE_ENCRYPT_STREAM_H_

#include <zlib.h>
#include <surbasic/AESHelper.h>
#include "dicom/storage/stream.h"
#include "dicom/storage/local_cache.h"
#include "dicom/upload/hash_cache.h"

namespace dicom {
class EncryptStream : public WriterStream {
 public:
  EncryptStream(const std::string& hexkey, WriterStream* out);
  virtual ~EncryptStream();

  int Write(const void* buf, size_t n);
  int Finalize();
  void Close();

  void GetHash(HashEntry* hash);

 private:
  static const int kBlockSize = 4096;
  SDBasic::aes::Aes256Encrypt cipher_;
  size_t src_size_;
  size_t enc_size_;
  WriterStream* out_;
  std::string hexkey_;

  dicom::MD5Helper src_md5_;
  dicom::SHA1Helper src_sha1_;
  dicom::SHA1Helper enc_sha1_;
  dicom::SHA512Helper src_sha512_;

  z_stream zstrm_;
  unsigned char outbuf_[kBlockSize];
};
}

#endif  // _DICOM_STORAGE_ENCRYPT_STREAM_H_
